package com.fg.pro.trade.controller;



import com.fg.pro.model.reponse.ResponseResult;
import com.fg.pro.trade.service.TradeGoodsService;
import com.fg.pro.trade.service.TradeUnitService;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;


/**
 * 单位(TradeUnit)表控制层
 *
 * @author makejava
 * @since 2025-08-13 09:37:31
 */
@Tag(name = "tradeUnit",description = "单位")
@RestController
@RequestMapping("tradeUnit")
public class TradeUnitController {
    /**
     * 服务对象
     */
    @Resource
    private TradeUnitService tradeUnitService;

    @Operation(summary = "获取单位分页",description = "")
    @GetMapping("/getPage")
    public ResponseResult getPage(@RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                  @RequestParam(required = false, defaultValue = "10") Integer pageSize){
        PageInfo pageInfo = tradeUnitService.getPage(pageNum,pageSize);
        return ResponseResult.okResult(pageInfo);
    }

    @Operation(summary = "刷新单位",description = "参数时间，可以不传参，默认刷新时间当前")
    @PostMapping("/refresh")
    public ResponseResult refresh(@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date date) throws InterruptedException {
        boolean flag = tradeUnitService.refresh(date);
        return ResponseResult.okResult(flag?"刷新成功":"正在刷新中。。。");
    }


}

